def debug_user_sim(user_sim): """ print user sim result :param user_sim:key userid value:[(userid1,score1),(userid2,score2)] :return: """ topk = 5 fix_user = "1" if fix_user not in user_sim: print("invalid user") return for zuhe in user_sim[fix_user][:topk]: userid, score = zuhe print(fix_user + "\tsim_user" + userid + "\t" + str(score))
用户推荐结果调试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
def debug_recom_result(item_info, recom_result): """ print recom result for user :param item_info: key itemid value:[title,genres] :param recom_result: key userid value dict, value_key:itemid value_value:recom_result :return: """ fix_user = "1" if fix_user not in recom_result: print("invalid user for recoming result") return for itemid in recom_result["1"]: if itemid not in item_info: continue recom_score = recom_result["1"][itemid] print("recom_result:" + ",".join(item_info[itemid]) + "\t" + str(recom_score))
算法改进1
1 2 3 4 5 6 7
def update_contribution_score(item_user_click_count): """ usercf user contribution score update v1 :param item_user_click_count: how many user have click this item :return: contribution score """ return 1 / math.log10(1 + item_user_click_count)